
/*
* Copyright (c) 2013 Robin Lee.
*
* Authors: Robin Lee <honeycombs@263.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program;
*/

#define _GNU_SOURCE

#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <unistd.h>

#ifndef __APPCMD_API_H_
#define __APPCMD_API_H_

#ifndef __externC
# ifdef __cplusplus
#  define __externC extern "C"
# else
#  define __externC extern
# endif
#endif

/*---------------------------------------------------------------------------------------------------------------------------------------------------
 * string
 */
__externC	char *appcmd_strim(char *s, const char *skip_str);

/*---------------------------------------------------------------------------------------------------------------------------------------------------
 * option
 */

typedef int (*appcmd_option_callback_t)( int, char*[], void *);

typedef struct appcmd_options_s
{
	const char*	name;	// option name
	const char*	help;	// option help
	appcmd_option_callback_t fun;	// option callback functions
	void* pri;	// private data
} appcmd_options_t;

/* diag option */
#define APPCMD_OPTION_FUNCTION_NAME(cmd)		appcmd_extoptf_##cmd

#define APPCMD_OPTION_FUNCTION(cmd) \
	static int APPCMD_OPTION_FUNCTION_NAME(cmd)( \
		int argc __attribute__((unused)), \
		char *argv[] __attribute__((unused)), \
		void *p __attribute__((unused)) )

#define APPCMD_OPTION(cmd,infomation,param) \
{	#cmd, infomation, \
	(appcmd_option_callback_t)(&APPCMD_OPTION_FUNCTION_NAME(cmd)), param \
}

#define APPCMD_OPTION_NULL	{NULL,NULL,NULL,NULL}

__externC	char *appcmd_strim(char *s, const char *skip_str);

__externC	int appcmd_parse_cmdline ( char* pstr, const char* split, char* argv[], int maxn);

__externC	int appcmd_options_runcmd(appcmd_options_t *opt_list, const char *fmt, ...);

#endif /* __APPCMD_API_H_ */
